import { BaseWindow } from "../../../component/window/BaseWindow";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Language } from "../../../../extend/language/Language";
import { ShopConfig } from "../../resource/ShopConfig";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EColor } from "../../../../Message/Public/EColor";
import { EProp } from "../../../../Message/Public/EProp";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { TilePanel } from "../equipment/TilePanel";
import { BossFieldStateCellRenderer } from "./cell/BossFieldStateCellRenderer";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { FlyFootBmp } from "../mapUI/flyFoot/FlyFootBmp";
import { BgItem } from "../common/BgItem";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { AIManager } from "../../scene/ai/AIManager";
import { AIType } from "../../scene/ai/AIType";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { BossFieldOrderData } from "./cellData/BossFieldOrderData";
import { SBossFieldInfo } from "../../../../Message/Public/SBossFieldInfo";
import { CrossBossFieldStateCellRenderer } from "./cell/CrossBossFieldStateCellRenderer";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class BossFieldEntranceWindow
    
    export  class BossFieldEntranceWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._bmpHonor1 = new Object /* flash.display.Bitmap */();
            this._bmpHonor4 = new Object /* flash.display.Bitmap */();
            this._bmpHonor100 = new Object /* flash.display.Bitmap */();
            this._bmpKillMonster = new Object /* flash.display.Bitmap */();
            this._bmpHonorImg = new Object /* flash.display.Bitmap */();
            this._bmpBattleHonor = new Object /* flash.display.Bitmap */();
            this.init();
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */resBattleComplete(): void
        {
            this._bmpHonor1.bitmapData = GlobalClass.getBitmapData(ImagesConst.honor1);
            this._bmpHonor4.bitmapData = GlobalClass.getBitmapData(ImagesConst.honor4);
            this._bmpHonor100.bitmapData = GlobalClass.getBitmapData(ImagesConst.honor100);
            this._bmpKillMonster.bitmapData = GlobalClass.getBitmapData(ImagesConst.killMonster);
            return;
        }

        /* internal  */resExchangeComplete(): void
        {
            this._bmpHonorImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.honorImg);
            this._bmpBattleHonor.bitmapData = GlobalClass.getBitmapData(ImagesConst.title_honor);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            if (Cache.instance.bossField.isCrossBossField) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossBossFieldRequestList));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BossFieldRequestList));
            }
            if (Cache.instance.role.money) 
            {
                this.updateMyHonor(Cache.instance.role.money.honour);
            }
            return;
        }

        /* internal  */init(): void
        {
            this.initBase();
            this.createChild();
            this.addListeners();
            return;
        }

        /* internal  */initBase(): void
        {
            titleHeight = 27;
            setSize(643, 472);
            title = Language.getString(41600);
            return;
        }

        public static hasInstance(): Boolean
        {
            return !(BossFieldEntranceWindow._instance == null);
        }

        public static get instance(): BossFieldEntranceWindow
        {
            if (!BossFieldEntranceWindow._instance) 
            {
                BossFieldEntranceWindow._instance = new BossFieldEntranceWindow();
            }
            return BossFieldEntranceWindow._instance;
        }

        /* internal  */updateItem(): void
        {
            var loc9=null;
            var loc10=0;
            var loc11=null;
            var loc1=3000;
            var loc2=Cache.instance.shop.getShopItemByCareer(Cache.instance.role.entityInfo.career, ShopConfig.instance.getShopByName(loc1));
            var loc3=new Array<any>();
            var loc4=new Array<any>();
            var loc5=new Array<any>();
            var loc6=0;
            while (loc6 < loc2.length) 
            {
                loc10 = (loc9 = loc2[loc6]).itemInfo.item.code;
                if (loc9.itemInfo.item.category == ECategory._ECategoryEquip && loc9.itemInfo.item.color == EColor._EColorPurple) 
                {
                    loc3.push(loc10);
                }
                else if (loc9.itemInfo.item.category == ECategory._ECategoryProp && loc9.itemInfo.item.type == EProp._EPropSkillBook) 
                {
                    loc4.push(loc10);
                }
                else 
                {
                    loc5.push(loc10);
                }
                ++loc6;
            }
            var loc7=(loc7 = (loc7 = (loc7 = new Array<any>()).concat(loc3)).concat(loc4)).concat(loc5);
            var loc8=0;
            while (loc8 < this._aryBgItem.length) 
            {
                if (loc8 < loc7.length) 
                {
                    (loc11 = this._aryBgItem[loc8]).setItemCode(loc7[loc8]);
                }
                ++loc8;
            }
            return;
        }

        /* internal  */createChild(): void
        {
            var loc3=null;
            var loc9=null;
            this._bg1 = ObjCreate.createBg(17, 38, 330, 142, this);
            this._bg2 = ObjCreate.createBg(17, 184, 330, 277, this);
            this._bg3 = ObjCreate.createBg(349, 38, 277, 423, this);
            this._spTipContainer = new Object /* flash.display.Sprite */();
            this._spTipContainer.x = 14;
            this._spTipContainer.y = 40;
            this._spTipContainer.mouseEnabled = false;
            this.addChild(this._spTipContainer);
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 11661311);
            loc1.leading = 7;
            loc1.indent = 24;
            var loc2=Language.getString(41601);
            this._tfTitle = ObjCreate.createTextField(Language.getString(41602), 11, 10, 90, 20, this._spTipContainer, new GTextFormat(FontUtil.songtiName, 12, 64767));
            this._tfContent = ObjCreate.createTextField(loc2, 11, 33, 320, 60, this._spTipContainer, loc1);
            this._tfContent.wordWrap = true;
            this._tfTime = ObjCreate.createTextField(Language.getString(41603), 11, 110, 320, 20, this._spTipContainer, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._spBossFieldContainer = new Object /* flash.display.Sprite */();
            this._spBossFieldContainer.x = 14;
            this._spBossFieldContainer.y = 183;
            this.addChild(this._spBossFieldContainer);
            this._tfBattleSelect = ObjCreate.createTextField(Language.getString(41604), 145, 10, 90, 20, this._spBossFieldContainer, new GTextFormat(FontUtil.songtiName, 12, 64767));
            this._crossBattleSelectTxt = ObjCreate.createGTextField("", 80, 10, 90, 20, this._spBossFieldContainer, new GTextFormat(FontUtil.songtiName, 12, 64767));
            this._enterTxt = ObjCreate.createGTextField(Language.getString(28052), 260, 10, 90, 20, this._spBossFieldContainer, new GTextFormat(FontUtil.songtiName, 12, 64767));
            this._tilePanelBattle = new TilePanel();
            this._tilePanelBattle.setSize(322, 240);
            this._tilePanelBattle.rowHeight = 60;
            this._tilePanelBattle.columnWidth = 316;
            this._tilePanelBattle.setStyle("cellRenderer", BossFieldStateCellRenderer);
            this._tilePanelBattle.x = 10;
            this._tilePanelBattle.y = 30;
            this._spBossFieldContainer.addChild(this._tilePanelBattle);
            this._rightPart = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._rightPart, 349, 38, -1, -1, this);
            ObjCreate.createTextField(Language.getString(41636), 9, 9, 200, 29, this._rightPart, GlobalStyle.textFormat6);
            loc3 = this.createRewardsSp(this._bmpHonor1, 14012283, 2);
            ObjCreate.setObjAttri(loc3, 15, 27, -1, -1, this._rightPart);
            loc3 = this.createRewardsSp(this._bmpHonor4, 14012284, 2);
            ObjCreate.setObjAttri(loc3, 15, 87, -1, -1, this._rightPart);
            loc3 = this.createRewardsSp(this._bmpHonor100, 14011590, 1, 14011591);
            ObjCreate.setObjAttri(loc3, 15, 147, -1, -1, this._rightPart);
            ObjCreate.createBg(10, 210, 255, 2, this._rightPart, "SplitLine");
            var loc4=ObjCreate.createBitmap(ImagesConst.PackItemBg, 13, 217, this._rightPart);
            ObjCreate.setObjAttri(this._bmpHonorImg, 16, 220, -1, -1, this._rightPart);
            ObjCreate.setObjAttri(this._bmpBattleHonor, 57, 216, -1, -1, this._rightPart);
            this._myHonor = ObjCreate.createTextField("", 60, 236, 120, 20, this._rightPart);
            ObjTeamCreate.setTextFieldKeyValue(this._myHonor, Language.getString(41637), "0", "#00FF00", "#f0ea3f");
            this._goToExchange = ObjCreate.createGButton(Language.getString(41638), 180, 213, 70, 20, this._rightPart, "LinkButton");
            this._goToExchange.addEventListener(flash.events.MouseEvent.CLICK, this.onGoToExchangeHandler);
            var loc5;
            (loc5 = new FlyFootBmp()).x = 243;
            loc5.y = 215;
            loc5.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            this._rightPart.addChild(loc5);
            ObjCreate.createBitmap(ImagesConst.Fire, 13, 250, this._rightPart);
            var loc6;
            (loc6 = ObjCreate.createTextField("", 35, 258, 240, 20, this._rightPart, GlobalStyle.textFormatGreen)).htmlText = Language.getString(41639);
            this._aryBgItem = new Array<any>();
            var loc7=0;
            while (loc7 < 12) 
            {
                (loc9 = new BgItem()).x = 17 + 40 * loc7 % 6;
                loc9.y = 277 + int(loc7 / 6) * 40;
                this._rightPart.addChild(loc9);
                this._aryBgItem.push(loc9);
                ++loc7;
            }
            ObjCreate.createBg(10, 358, 255, 2, this._rightPart, "SplitLine");
            ObjCreate.createTextField(Language.getString(41640), 12, 367, 75, 20, this._rightPart);
            this._bmpKillMonster.x = 90;
            this._bmpKillMonster.y = 362;
            this._rightPart.addChild(this._bmpKillMonster);
            var loc8;
            (loc8 = GlobalStyle.textFormat1).leading = 5;
            (loc6 = ObjCreate.createTextField("", 15, 385, 252, 40, this._rightPart, loc8)).multiline = true;
            loc6.wordWrap = true;
            loc6.htmlText = Language.getString(41641);
            this._tfLookTop = ObjCreate.createTextField("", 195, 402, 90, 20, this._rightPart, GlobalStyle.textFormatGreen);
            this._tfLookTop.htmlText = Language.getString(41642);
            this._tfLookTop.addEventListener(flash.events.TextEvent.LINK, this.onLookTopHandler);
            this.updateItem();
            return;
        }

        /* internal  */onGoToExchangeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectHonsExchange);
            AIManager.onAutoPathAIControl(loc1);
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectHonsExchange);
            AIManager.onAIControl(loc1, AIType.AI_Convey);
            return;
        }

        /* internal  */onLookTopHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankSelectedAssignType, {"oneIdx": 2, "twoIdx": 0}));
            return;
        }

        /* internal  */createRewardsSp(arg1: Object /* flash.display.Bitmap */, arg2: int, arg3: int=1, arg4: int=0): Object /* flash.display.Sprite */
        {
            var loc1;
            (loc1 = new Object /* flash.display.Sprite */()).addChild(arg1);
            var loc2=ObjCreate.createTextField(Language.getString(41643), 0, 30, 40, 20, loc1);
            if (!(arg4 == 0) && Cache.instance.role.entityInfo.level >= 60) 
            {
                arg2 = arg4;
            }
            var loc3=new ItemData(arg2);
            var loc4;
            (loc4 = ObjCreate.createTextField("", 40, 30, 90, 20, loc1)).htmlText = ItemsUtil.getItemName(loc3);
            var loc5;
            (loc5 = new BgItem()).setItemCode(arg2, arg3);
            ObjCreate.setObjAttri(loc5, 137, 19, -1, -1, loc1);
            return loc1;
        }

        /* internal  */addListeners(): void
        {
            LoaderHelp.addResCallBack(ResFileConst.battlefiledEnter, this.resBattleComplete);
            LoaderHelp.addResCallBack(ResFileConst.exchange, this.resExchangeComplete);
            return;
        }

        public updateBossFieldList(arg1: Array<any>, arg2: int=-1): void
        {
            var loc3=null;
            var loc4=0;
            var loc1=new Array<any>();
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                if (arg2 > -1) 
                {
                    loc1.push(new BossFieldOrderData(loc2 + 1, arg1[loc2] as SBossFieldInfo, arg2));
                }
                else 
                {
                    loc1.push(new BossFieldOrderData(loc2 + 1, arg1[loc2] as SBossFieldInfo));
                }
                ++loc2;
            }
            if (Cache.instance.bossField.isCrossBossField) 
            {
                this._tilePanelBattle.rowHeight = 80;
                this._tilePanelBattle.setStyle("cellRenderer", CrossBossFieldStateCellRenderer);
                loc3 = "";
                if (loc1.length > 0) 
                {
                    loc4 = BossFieldOrderData(loc1[0]).force;
                    loc3 = HTMLUtil.addColor(GameDefConfig.instance.getCrossBossFieldName(loc4), ColorConfig.instance.getCampColor(loc4).color);
                }
                this._crossBattleSelectTxt.htmlText = Language.getStringByParam(28051, loc3);
                DisplayUtil.removeMe(this._tfBattleSelect);
                this._spBossFieldContainer.addChild(this._crossBattleSelectTxt);
                this._spBossFieldContainer.addChild(this._enterTxt);
            }
            else 
            {
                this._tilePanelBattle.rowHeight = 60;
                this._tilePanelBattle.setStyle("cellRenderer", BossFieldStateCellRenderer);
                DisplayUtil.removeMe(this._enterTxt);
                DisplayUtil.removeMe(this._crossBattleSelectTxt);
                this._spBossFieldContainer.addChild(this._tfBattleSelect);
            }
            this._tilePanelBattle.dataProvider = new DataProvider(loc1);
            this._tilePanelBattle.drawNow();
            return;
        }

        public updateMyHonor(arg1: int): void
        {
            ObjTeamCreate.setTextFieldKeyValue(this._myHonor, Language.getString(41637), arg1.toString(), "#00FF00", "#f0ea3f");
            return;
        }

        /* internal */ /* var */_tfContentTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTimeTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_bg1: ScaleBitmap;

        /* internal */ /* var */_bg2: ScaleBitmap;

        /* internal */ /* var */_bg3: ScaleBitmap;

        /* internal */ /* var */_spTipContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfTitle: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfContent: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTime: Object /* flash.text.TextField */;

        /* internal */ /* var */_spBossFieldContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfBattleSelect: Object /* flash.text.TextField */;

        /* internal */ /* var */_crossBattleSelectTxt: GTextFiled;

        /* internal */ /* var */_enterTxt: GTextFiled;

        /* internal */ /* var */_tilePanelBattle: TilePanel;

        /* internal */ /* var */_rightPart: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bmpHonor1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpHonor4: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_aryBgItem: Array<any>;

        /* internal */ /* var */_tfLookTop: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpKillMonster: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpHonor100: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpHonorImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpBattleHonor: Object /* flash.display.Bitmap */;

        /* internal */ static /* var */_instance: BossFieldEntranceWindow;

        /* internal */ /* var */_myHonor: Object /* flash.text.TextField */;

        /* internal */ /* var */_goToExchange: GButton;
    }
